<?php

require_once(dirname(__FILE__) . '/EventDispatcher.php');

/**
 * Singleton for regular "background" execuiton
 * @author Gvozd
 */
class Tick extends EventDispatcher {

    static private $instance;

    private function __construct() {}

    private function __clone() {}

    /**
     * @return Tick
     */
    public static function getInstance() {
        if (null === self::$instance)
            self::$instance = new Tick();
        return self::$instance;
    }

    /**
     * Start regular execution in cycle, while something to do
     */
    public function startExecution() {
        while ($this->hasSomeEventListener()) {
            usleep(10000);
            $this->dispatchEvent(new Event('tick'));
            //file_put_contents(ABSPATH . 'tick.export',var_export($this->events, true) );
        }
    }

}